import 'package:flutter/material.dart';
import 'carousel_slider.dart';
import 'productList.dart';

Color bg = const Color(0xFFf4f4f4);
Color btnBg = const Color(0xFFFF8954);

class NotificationsCom extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      color:  Colors.white,
      height: 40,
      padding:const EdgeInsets.only(left: 10.0),
      child: Row(
        children: <Widget>[
          Icon(Icons.notifications_none,color: Colors.red,),
          Text('用户136 **** 0614成功借款1500元')
        ]
      )
    );
  }
}

class RecommendProCom extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      color:  Colors.white,
      height: 43,
      margin: const EdgeInsets.only(top: 10.0),
      padding:const EdgeInsets.only(left: 10.0),
      child: Row(
        children: <Widget>[
          Row(
            children:<Widget>[
              Icon(Icons.whatshot,color: Colors.red),
              Text('产品推荐', style: TextStyle(color: Colors.red))
            ]
          ),
          new Expanded(
            child: Center(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children:<Widget>[
                  Text('查看更多'),
                  Icon(Icons.keyboard_arrow_right),
                ]
              ),
            )
          )
        ]
      )
    );
  }
}

class SliverScreen extends StatefulWidget {
  @override
  _SliverScreenState createState() => _SliverScreenState();
}

class _SliverScreenState extends State<SliverScreen> {
  ScrollController _controller;

  @override
  void initState() {
    super.initState();
    _controller = ScrollController();
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        controller: _controller,
        slivers: <Widget>[
          _buildSliverToBoxAdapter(),
          // _buildSliverAppBar(),
          _buildSliverFixedExtentList(context),
        ],
      ),
    );
  }

  Widget _buildSliverToBoxAdapter(){
    return SliverToBoxAdapter(
      child: Column(
        children: <Widget>[
          CarouselWithIndicator(),
          NotificationsCom(),
          RecommendProCom()
        ],
      )
    );
  }


  Widget _buildSliverAppBar(){
    return SliverAppBar(
      backgroundColor: Colors.white.withOpacity(0.5),
      expandedHeight: 200.0,
//            floating: true,
      pinned: true,
      flexibleSpace: FlexibleSpaceBar(
          centerTitle: false,
          title: Text('产品推荐'),
          background: Image.network(
            "https://www.snapphotography.co.nz/wp-content/uploads/New-Zealand-Landscape-Photography-prints-12.jpg",
            fit: BoxFit.cover,
          )),
    );
  }

  Widget _buildSliverFixedExtentList(BuildContext context){
    return Container(
      child: ProductList(),
    );
  }
}